package com.sia.springcloud.protocol.model;

import com.sia.springcloud.model.Point;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author: Sirius
 * @Date: 2022/1/2 15:19
 * @Description:
 **/

@Data
public class OpcuaPoint implements Serializable {

    private Integer id;
    private Integer collect;
    private Integer deviceId;
    private String protocolName;
    private String PointName;
    private String tagName;
    private Integer namespace;
    private Integer type;
    private Integer frequency;
    private String metricName;
    private String target;
    private String domain;
    private Integer sendFrequency;
    private String scale;

    private static final long serialVersionUID = 1L;

    /**
     * 将Modbus变量对象转换成协议变量对象
     *
     * @param opcuaPoint
     * @return
     */
    public static Point convert(OpcuaPoint opcuaPoint) {
        Point point = new Point();
        point.setId(opcuaPoint.getId());
        point.setCollect(opcuaPoint.getCollect());
        point.setDeviceId(opcuaPoint.getDeviceId());
        point.setProtocolName(opcuaPoint.getProtocolName());
        point.setPointName(opcuaPoint.getPointName());
        point.setTagname(opcuaPoint.getTagName());
        point.setVarInt1(opcuaPoint.getNamespace());
        point.setType(opcuaPoint.getType());
        point.setFrequency(opcuaPoint.getFrequency());
        point.setMetricName(opcuaPoint.getMetricName());
        point.setTarget(opcuaPoint.getTarget());
        point.setDomain(opcuaPoint.getDomain());
        point.setSendFrequency(opcuaPoint.getSendFrequency());
        point.setScale(opcuaPoint.getScale());

        return point;
    }

    /**
     * 将Protocol变量对象转换成opcua变量对象
     *
     * @param point
     * @return
     */
    public static OpcuaPoint reconvert(Point point) {
        OpcuaPoint opcuaPoint = new OpcuaPoint();
        opcuaPoint.setId(point.getId());
        opcuaPoint.setCollect(point.getCollect());
        opcuaPoint.setDeviceId(point.getDeviceId());
        opcuaPoint.setProtocolName(point.getProtocolName());
        opcuaPoint.setPointName(point.getPointName());
        opcuaPoint.setTagName(point.getTagname());
        opcuaPoint.setNamespace(point.getVarInt1());
        opcuaPoint.setType(point.getType());
        opcuaPoint.setFrequency(point.getFrequency());
        opcuaPoint.setMetricName(point.getMetricName());
        opcuaPoint.setTarget(point.getTarget());
        opcuaPoint.setDomain(point.getDomain());
        opcuaPoint.setSendFrequency(point.getSendFrequency());
        opcuaPoint.setScale(point.getScale());

        return opcuaPoint;
    }

}

